package com.asia.order.utils;

import org.apache.commons.codec.digest.DigestUtils;

public class SignAlgorithm {

    public static String signByAlgorithm(SignAlgorithmEnum signType,String data,boolean toUpperCase){
        String signResult = "";
        switch (signType){
            case MD2:signResult = DigestUtils.md2Hex(data);break;
            case MD5:signResult = DigestUtils.md5Hex(data);break;
            case SHA1:signResult = DigestUtils.sha1Hex(data);break;
            case SHA256:signResult = DigestUtils.sha256Hex(data);break;
            case SHA384:signResult = DigestUtils.sha384Hex(data);break;
            case SHA512:signResult = DigestUtils.sha512Hex(data);break;
            default:throw new IllegalArgumentException(signType.name()+"签名算法暂不支持");
        }
        return toUpperCase?signResult.toUpperCase():signResult;
    }
}
